using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using HeThongDAO;
using NUnit.Framework;
using System.Data;

namespace _041346_1041351_1041352_UnitTest
{
    [TestFixture]
    public class TestBaoCaoTon
    {
        [Test]
        public void TestBaoCaoTon1()
        {
            double slTon = 100;
            SachDTO sa = new SachDTO();
            sa.IMaSach = 1;
            DataTable dttongnhap = SachDAO.LayTongNhapTuThang(sa, 5, 2011);
            DataTable dttongban = SachDAO.LayTongBanTuThang(sa, 5, 2011);
            double tondau = 0;
            double tongnhap_tuthang = 0;
            double tongxuat_tuthang = 0;
            try
            {
                DataRow drtongnhap_tuthang = dttongnhap.Rows[0];
                tongnhap_tuthang = double.Parse(drtongnhap_tuthang["TongNhap"].ToString());
            }
            catch
            {

            }
            try
            {
                DataRow drtongban_tuthang = dttongban.Rows[0];
                tongxuat_tuthang = double.Parse(drtongban_tuthang["TongBan"].ToString());
            }
            catch
            {

            }
            tondau = slTon + tongxuat_tuthang - tongnhap_tuthang;

            dttongnhap = SachDAO.LayTongNhapTrongThang(sa, 5, 2011);
            dttongban = SachDAO.LayTongBanTrongThang(sa, 5, 2011);
            double tongnhap_trongthang = 0;
            double tongxuat_trongthang = 0;
            try
            {
                DataRow drtongnhap_trongthang = dttongnhap.Rows[0];
                tongnhap_trongthang = double.Parse(drtongnhap_trongthang["TongNhap"].ToString());
            }
            catch
            {

            }
            try
            {
                DataRow drtongban_trongthang = dttongban.Rows[0];
                tongxuat_trongthang = double.Parse(drtongban_trongthang["TongBan"].ToString());
            }
            catch
            {

            }
            double phatsinh = tongnhap_trongthang - tongxuat_trongthang;
            double toncuoi = tondau + (tongnhap_trongthang - tongxuat_trongthang);

            //du lieu so sanh 
            double testtondau = 104;
            double testphatsinh = -4;
            double testtoncuoi = 100;

            Assert.AreEqual(testtondau, tondau);
            Assert.AreEqual(testtoncuoi, toncuoi);
            Assert.AreEqual(testphatsinh, phatsinh);
        }
        [Test]
        public void TestBaoCaoTon2()
        {
            double slTon = 120;
            SachDTO sa = new SachDTO();
            sa.IMaSach = 2;
            DataTable dttongnhap = SachDAO.LayTongNhapTuThang(sa, 5, 2011);
            DataTable dttongban = SachDAO.LayTongBanTuThang(sa, 5, 2011);
            double tondau = 0;
            double tongnhap_tuthang = 0;
            double tongxuat_tuthang = 0;
            try
            {
                DataRow drtongnhap_tuthang = dttongnhap.Rows[0];
                tongnhap_tuthang = double.Parse(drtongnhap_tuthang["TongNhap"].ToString());
            }
            catch
            {

            }
            try
            {
                DataRow drtongban_tuthang = dttongban.Rows[0];
                tongxuat_tuthang = double.Parse(drtongban_tuthang["TongBan"].ToString());
            }
            catch
            {

            }
            tondau = slTon + tongxuat_tuthang - tongnhap_tuthang;

            dttongnhap = SachDAO.LayTongNhapTrongThang(sa, 5, 2011);
            dttongban = SachDAO.LayTongBanTrongThang(sa, 5, 2011);
            double tongnhap_trongthang = 0;
            double tongxuat_trongthang = 0;
            try
            {
                DataRow drtongnhap_trongthang = dttongnhap.Rows[0];
                tongnhap_trongthang = double.Parse(drtongnhap_trongthang["TongNhap"].ToString());
            }
            catch
            {

            }
            try
            {
                DataRow drtongban_trongthang = dttongban.Rows[0];
                tongxuat_trongthang = double.Parse(drtongban_trongthang["TongBan"].ToString());
            }
            catch
            {

            }
            double phatsinh = tongnhap_trongthang - tongxuat_trongthang;
            double toncuoi = tondau + (tongnhap_trongthang - tongxuat_trongthang);

            //du lieu so sanh 
            double testtondau = 97;
            double testphatsinh = 3;
            double testtoncuoi = 100;

            Assert.AreEqual(testtondau, tondau);
            Assert.AreEqual(testtoncuoi, toncuoi);
            Assert.AreEqual(testphatsinh, phatsinh);

        }
        
    }
}
